package com.yanqu.road.server.cmd.activity.autoreward;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.AutoSendRewardProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.cmd.activity.autoreward.rank.BaseCrossRank;
import com.yanqu.road.server.cmd.activity.autoreward.rank.CrossRankFactory;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = CrossProtocol.C_CROSS_AUTO_SEND_UNION_RANK_LIST_FOR_UNION_GROUP, desc = "")
public class CrossActivityUnionRankLsitForUnionGroupCmd extends CrossUnionCommand {

    private int activityId;
    private int activityType;
    private int childType;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        AutoSendRewardProto.NoticeCrossUnionRankMsg msg = AutoSendRewardProto.NoticeCrossUnionRankMsg.parseFrom(packet.getBytes());
        activityId = msg.getActivityId();
        activityType = msg.getActivityType();
        childType = msg.getChildType();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        BaseCrossRank crossRank = CrossRankFactory.getCrossRank(activityId, activityType, childType);
        AutoSendRewardProto.CrossUnionRankMsg.Builder msg = null;
        if (crossRank != null) {
            msg = crossRank.getCrossUnionRankMsg(groupId);
        }
        if (msg == null) {
            msg = AutoSendRewardProto.CrossUnionRankMsg.newBuilder();
            msg.setActivityId(activityId);
        }
        YanQuMessage message = YanQuMessageUtils.buildMessage(GameProtocol.S_CROSS_ACTIVITY_AUTO_SEND_UNION_REWARD, msg);
        MessageHelper.sendPacket(serverId, 0, message);
    }

    @Override
    public void sendData() {

    }
}
